package com.pond.auth.util.sms;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class SmsUtil {

    @Value("${sms.provider}") // 例：ihuyi 或 aliyun
    private String provider;

    private final Map<String, SmsSender> senderMap;

    public SmsUtil(Map<String, SmsSender> senderMap) {
        this.senderMap = senderMap;
    }

    public boolean sendCode(String phone, String code) {
        SmsSender sender = senderMap.get(provider + "SmsSender"); // 关键逻辑
        if (sender == null) {
            throw new RuntimeException("未找到对应的短信服务实现: " + provider);
        }
        return sender.sendCode(phone, code);
    }
}
